from flask import Flask
from flask import url_for
app = Flask(__name__)


@app.route("/")
def index():
    return f"<h1>这里是首页</h1>"


# @app.route("/detail/<bid>/")
@app.route("/detail/<int:bid>/")
def detail(bid):
    print(type(bid))
    return f"<h1>这里是详情{bid}</h1>"


@app.route("/media/<path:path>/")
def media(path):
    print(type(path))
    return f"你访问的资源是{path}"


def main():
    app.run(debug=True)


with app.test_request_context():
    # 路由解除硬编码
    print(url_for("index"))
    print(url_for("detail", bid=101))
    print(url_for("media", path="head/1234.png"))

    # 静态资源解除硬编码
    print(url_for('static', filename="bootstrap/css/bootstrap.main.css"))


if __name__ == '__main__':
    main()
